package simulator.enums;

public enum LightState
{
	/* show green light */
	GREEN("green", true),
	/* show orange light */
	ORANGE("yellow", false), //spec uses yellow, we want EU intersection with orange lights
	/* show red light */
	RED("red", false),
	/* continuously blink orange */
	BLINK("blink", true),
	/* continuously blink red (traffic light internal error; out of spec) */
	BLINK_ERR("null", false),
	/* show nothing */
	OFF("off", true),
	/* show left signal (bus) <out of spec> */
	LEFT("left", true),
	/* show right signal (bus) <out of spec> */
	RIGHT("right", true),
	/* show straight signal (bus) <out of spec> */
	STRAIGHT("straight", true),
	/* show 'any direction' signal (bus) <out of spec -and- assignment> */
	ALL("all", true);
	
	private String _specStr;
	private boolean _continue;
	
	private LightState(String spec, boolean cont)
	{
		_specStr = spec;
		_continue = cont;
	}
	
	public String getSpecString()
	{
		return _specStr;
	}
	
	public boolean canContinue()
	{
		return _continue;
	}
	
	public static LightState fromString(String str)
	{
		/* normal states */
		if("green".equalsIgnoreCase(str))
			return GREEN;
		if("yellow".equalsIgnoreCase(str) || "orange".equalsIgnoreCase(str))
			return ORANGE;
		if("red".equalsIgnoreCase(str))
			return RED;
		if("blink".equalsIgnoreCase(str))
			return BLINK;
		if("off".equalsIgnoreCase(str))
			return OFF;
		
		/* bus states: not in spec */
		if("left".equalsIgnoreCase(str))
			return LEFT;
		if("right".equalsIgnoreCase(str))
			return RIGHT;
		if("straight".equalsIgnoreCase(str))
			return STRAIGHT;
		/* bus states: not in spec -and- assignment (although present on actual dutch bus traffic lights)
		 * but used to work around spec limitations since it thinks bus traffic lights are the same as car traffic lights. Fills the duty of 'green'. 
		 */
		if("all".equalsIgnoreCase(str))
			return ALL;
		
		/* unknown string: return error blink */
		return BLINK_ERR;
	}
}
